/** ***********************************************
 * CodeGen
 *
 * @author  Jonnie Spratley
 * @date 3/05/2009
 * @licence MCIYC
 * @website http://jonniespratley.com/code
 * @contact jonniespratley@gmail.com
 *********************************************** */
package com.jonniespratley.codegen.vo
{
	import mx.collections.ArrayCollection;


	[Bindable]
	public class PHPMethodVO
	{
		
		public var methodClass:String;
		public var methodName:String;
		public var methodComments:String;
		public var methodParamCount:String;
		public var methodRequiredParamCount:String;


		public var isFinal:String;
		public var isStatic:String;
		public var isAbstract:String;

		public var methodParams:ArrayCollection;

		public function  PHPMethodVO( obj:Object = null )
		{
			if ( obj != null )
			{
				this.methodClass = obj['methodClass'];
				this.methodName = obj['methodName'];
				this.methodComments = cleanComments( obj['methodComments'] );
				this.isFinal = obj['isFinal'];
				this.isStatic = obj['isStatic'];
				this.isAbstract = obj['isAbstract'];
				this.methodParamCount = obj['methodParamCount'];
				this.methodRequiredParamCount = obj['methodRequiredParamCount'];

				if ( obj['methodParams'] != null )
				{
					//set the fields comming back as an Array
					var tempArray:Array = obj['methodParams'] as Array;

					//create a temp arraycollection so return to the aFields
					var tempAc:ArrayCollection = new ArrayCollection();

					//loop through every string in the fields array
					for ( var s:String in tempArray )
					{
						//for each object add it to the temp collection
						tempAc.addItem( new PHPParamVO( tempArray[ s ] ) );
					}
					//set the array collection to the build one of value objects
					this.methodParams = tempAc;
				}
			}
		}


		/* public function get children():Array
		{
			return this.methodParams.toArray();
		} */

		public function get label():String
		{
			return this.methodName /*+ '('+ methodParams.toArray().toString() +')'*/;
		}

		/* public function get icon():Class
		{
			return this.methodIcon;
		} */

		public function toString():String
		{
			return this.methodName + ' ( ' + this.methodParams.toString() + ' )';
		}

		private function cleanComments( str:String ):String
		{
			//@param
			var pattern1:RegExp = /(@)/;
			var pattern2:RegExp = /(@param)/;
			return str.replace( pattern1, '\n' ).replace( pattern2, '\nparam: ' );
		}

	}
}